package com.shawn.model.vo;

import com.shawn.commons.utils.RC;
import com.shawn.model.entity.UserInfo;
import com.shawn.model.mongo.Comment;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author shawn
 * @date 2022年 12月 21日 16:04
 */
@Data
public class CommentBackendVo {
    private String id;//评论id
    private String nickname;//昵称
    private Integer userId;
    private String content;//评论内容
    private Date createDate;//评论时间

    //提供快速转换方法
    public static CommentBackendVo init(Comment comment, UserInfo userInfo) {
        CommentBackendVo commentsVo = new CommentBackendVo();
        BeanUtils.copyProperties(comment, commentsVo);
        commentsVo.setUserId(comment.getUserId().intValue());
        commentsVo.setId(comment.getId().toHexString());
        //转换评论时间
        commentsVo.setCreateDate(new Date(comment.getCreated()));
        commentsVo.setNickname(userInfo.getNickname());
        return commentsVo;
    }
}
